package 第五天

fun main() {
    // for foreach 过滤
    val list = listOf<String>("张三", "张三2", "李四")
    val list1 = listOf<String>("张五", "张六", "李四")
    //过滤姓张的数据
    val resultList = list.filter {
        it.startsWith("张")
    }

    val mulist = mutableListOf<String>()
    list.filterTo(mulist) {
        it.startsWith("张")
    }
    list1.filterTo(mulist) {
        it.startsWith("张")
    }

    //过滤角标为偶数的数据
    val result =  list.filterIndexed { index, s ->
        index % 2 == 0
    }
    println(result)
}